package com.siwei.mes.controller.system;

import com.siwei.mes.common.result.ApiResult;
import com.siwei.mes.common.result.Json;
import com.siwei.mes.entity.MaterialsTestProject;
import com.siwei.mes.mapper.MaterialsTestProjectMapper;
import com.siwei.mes.service.MaterialsService;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 物料表相关
 *
 * @author linzi
 * @since 2023-11-27 22:46:48
 */
@Api(value = "物料表")
@RestController
@RequestMapping("materials")
public class MaterialsController {
    @Resource
    private MaterialsService materialsService;
    @Resource
    private MaterialsTestProjectMapper materialsTestProjectMapper;

    /**
     * 根据物料类型获取所有物料名称  可以不传
     *
     * @param materialType 物料类型 字典 MATERIAL_TYPE
     * @return
     */
    @GetMapping("getMaterialsNameByType")
    public Json getMaterialsName(@RequestParam(required = false, name = "materialType") Long materialType) {
        return Json.succ().data(ApiResult.addList(materialsService.getMaterialsNameByType(materialType)));
    }

    /**
     * 根据物料名称获取对应的物料规格
     *
     * @param materialName 物料名称
     * @param materialType 物料类型 字典 MATERIAL_TYPE
     * @return
     */
    @GetMapping("getMaterialsSpecs")
    public Json getMaterialsSpecs(@RequestParam("materialName") String materialName,
                                  @RequestParam(required = false, name = "materialType") Long materialType) {
        return Json.succ().data(ApiResult.addList(materialsService.getMaterialsSpecs(materialName, materialType)));
    }

    /**
     * 根据物料类型获取对应的试验项目
     *
     * @param materialType 物料类型 字典 MATERIAL_TYPE
     * @return
     */
    @GetMapping("getTestProject")
    public Json getTestProject(@RequestParam("materialType") Long materialType) {
        MaterialsTestProject entity = new MaterialsTestProject();
        entity.setMaterialType(materialType);
        List<MaterialsTestProject> all = materialsTestProjectMapper.getList(entity);
        return Json.succ().data(ApiResult.addList(all));
    }

}
